<?php 
## include required files
/*******************************/
require_once '../../includefiles.php';
require_once '../../model/users.php';
require_once '../../model/membershipplan.php';
require_once "../../includes/classes/paging_htacess.php";
require_once '../../redirect.php';

## creating objects of required models
$userObj 		= new Model_Users();
$planObj 		= new Model_PLAN();

checkUserLogin();

if($_SESSION['user_type'] == '3')
{
	@header("location:".SITE_URL."/");
	exit;
}


$userId =$_SESSION['getbids_id'];

## When user wants to delete the testimonial
if($_GET['id1'] == 'delete' && $_GET['id2']!='')
{
	$transID = base64_decode($_GET['id2']);
	$userObj->deleteTransactionById($transID);
	$_SESSION['msg'] = "<div class='success_msg'style='margin-top:5px;margin-bottom: 20px;'><span>History deleted successfully !</span></div>";
	header("Location:".SITE_URL."/payment/history/");
	exit;
}

## for pagination
	$page = $_GET['id1'];
	if(!isset($_GET['id1']))
	$page = 1;
	else
	$page = $page;
	
## limit per pag 
$tetsimonialPerPage =10;
$StartRow = $tetsimonialPerPage  * ($page-1);
## Getting all leads from database according to user
## search value
if($_REQUEST['paymentfor']!='0'){
	$paymentfor = addslashes(trim($_REQUEST['paymentfor']));
} else {
	$paymentfor = '';
}
//$smarty->assign('searchindex',$searchindex);
if($_REQUEST['from_date']!=''){
	$from_date = $_REQUEST['from_date'];
} else {
	$from_date = '';
}
if($_REQUEST['to_date']!='To Date'){
	$to_date = $_REQUEST['to_date'];
} else {
	$to_date = '';
}
$historyArray  = $userObj->paymentHistoryAccordingToUserId($userId,$paymentfor,$from_date,$to_date,'','',false);
$totalCount        = count($historyArray);
$smarty -> assign("recordsFound",$totalCount);

$result = $userObj->paymentHistoryAccordingToUserId($userId,$paymentfor,$from_date,$to_date,$tetsimonialPerPage,$StartRow,true);
$show = 1;
$total_pages = ceil($totalCount / $tetsimonialPerPage);
	if($total_pages > 1)
	$smarty -> assign("showpgnation","yes");
	$showing    = !isset($_GET["id1"]) ? 1 : $page;
	
	## it shoould be file name 
	$firstlink  = "payment/history/";
	
	$baselink   = $firstlink;
	if($total_pages!=0)
		$pagenation = pagination($total_pages, $show, $showing, $firstlink, $baselink, "", "payment");
	$smarty -> assign("pagenation", $pagenation);
	$smarty -> assign("page", $page);
	//
	for($i=0;$i<count($result);$i++)
	{
		$getplandetail = $planObj->getPlanDetailsById($result[$i]['plan_id']);					
		if($getplandetail['name']!='')
		{
			$result[$i]['planname'] = $getplandetail['name'];
		}
		else
		{
			$result[$i]['planname'] = '-';
		}
	}
	
	$smarty->assign("historyArray", $result);
	
/*===========================================================================*/
	$userDetArray = $userObj->getUserDetailsByUserId($userId);
	$smarty->assign("userDetArray", $userDetArray);	
	
/*===========================================================================*/	




if($_SESSION['msg']){
		$smarty->assign("msg", $_SESSION['msg']);
		unset($_SESSION['msg']);
}

$active ="myaccount";
$smarty->assign('active',$active);
$subactive ="mypaymenthistory";
$smarty->assign('subactive',$subactive);
$smarty->assign('mainmenu',"7");

$smarty->display(TEMPLATEDIR.'/modules/payment/history.tpl');
unset($smarty);
?>
